package com.hmall.search.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.pojo.Item;
import com.hmall.search.mapper.ItemMapper;
import com.hmall.search.service.ISearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SearchService extends ServiceImpl<ItemMapper, Item> implements ISearchService {
    private final StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues = "item.id")
    public void clearCache(String itemId) {
        if (StrUtil.isNotEmpty(itemId)) {
            stringRedisTemplate.delete("hot:item:top20");
        }
    }
}
